<template>
  <div>
    <tableComponents :pagination="{currentPage,pageSize,total:list.all_num}" @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange" @sendUserSearch="receive_search" :searchData="userSearchData" :isHaveExport="false" :isHaveAdd="false">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="list.data" stripe v-loading="loading" header-row-class-name="head_color" tooltip-effect="dark"
            style="width: 99.8%" @selection-change="handleSelectionChange">
          <el-table-column type="selection" class="tc" width="35"></el-table-column>

          <el-table-column label="头像" min-width="80">
            <template slot-scope="scope">
              <div class="img_bor_tx">
                <img :src="$fnc.getImgUrl(scope.row.avatar)" alt />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="用户信息" min-width="160">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>用户昵称：</span>
                  <span>{{scope.row.nickname || '----'}}</span>
                </div>
                <div>
                  <span>会员账号：</span>
                  <span>{{scope.row.username ||'---'}}</span>
                </div>
                <div>
                  <span>IM：</span>
                  <span>{{scope.row.im || '----'}}</span>
                </div>
                <div>
                  <span>注册时间：</span>
                  <span>{{scope.row.created_time |getTimeFormat}}</span>
                </div>
                <div>
                  <span>最近登录时间：</span>
                  <span>{{scope.row.login_time |getTimeFormat}}</span>
                </div>
                <div>
                  <span>手机号：</span>
                  <span>{{scope.row.tel ||'---'}}</span>
                </div>
                <div v-if="scope.row.tid > 0">
                  <span>推荐人昵称：</span>
                  <span>{{scope.row.t_nickname ||'---'}}</span>
                </div>
                <div v-if="scope.row.tid > 0">
                  <span>推荐人账号：</span>
                  <span>{{scope.row.t_username ||'---'}}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="is_jianqun" label="允许建群" min-width="125">
            <template slot-scope="scope">
              <el-switch class="zdySwith" :width="82" v-model="scope.row.is_jianqun" active-color="#1aad19" inactive-color="#ffffff" active-text="已开启"
                  inactive-text="已禁止" active-value="1" @change="change_switch($event, scope.row, 'is_jianqun')" inactive-value="0"></el-switch>
            </template>
          </el-table-column>
          <el-table-column prop="is_friends" label="允许加好友" min-width="125">
            <template slot-scope="scope">
              <el-switch class="zdySwith" :width="82" v-model="scope.row.is_friends" active-color="#1aad19" inactive-color="#ffffff" active-text="已开启"
                  inactive-text="已禁止" active-value="1" @change="change_switch($event, scope.row, 'is_friends')" inactive-value="0"></el-switch>
            </template>
          </el-table-column>
          <el-table-column prop="is_moments" label="开放朋友圈" min-width="125">
            <template slot-scope="scope">
              <el-switch class="zdySwith" :width="82" v-model="scope.row.is_moments" active-color="#1aad19" inactive-color="#ffffff" active-text="已开启"
                  inactive-text="已禁止" active-value="1" @change="change_switch($event, scope.row, 'is_moments')" inactive-value="0"></el-switch>
            </template>
          </el-table-column>
          <el-table-column prop="is_red" label="允许发红包" min-width="125">
            <template slot-scope="scope">
              <el-switch class="zdySwith" :width="82" v-model="scope.row.is_red" active-color="#1aad19" inactive-color="#ffffff" active-text="已开启"
                  inactive-text="已禁止" active-value="1" @change="change_switch($event, scope.row, 'is_red')" inactive-value="0"></el-switch>
            </template>
          </el-table-column>
          <el-table-column prop="show" label="是否冻结" min-width="125">
            <template slot-scope="scope">
              <el-switch class="zdySwith" :width="82" v-model="scope.row.show" active-color="#1aad19" inactive-color="#ffffff" active-text="已开启"
                  inactive-text="已禁止" active-value="1" @change="change_switch($event, scope.row, 'show')" inactive-value="0"></el-switch>
            </template>
          </el-table-column>
          <el-table-column label="操作" min-width="120">
            <template slot-scope="scope">
              <el-row class="myblank">
                <el-button :loading="$store.state.isLoading" size="mini" @click="editbtn(scope.row)" type="primary">编辑</el-button>
                <el-button :loading="$store.state.isLoading" size="mini" type="danger" @click="deletebtn( scope.row.id)">清空IM帐号</el-button>
              </el-row>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <template v-slot:footerLeft>
        <a class="aBtn aBtn_1 aBtn_lan2" @click="deleteAll">删除</a>
      </template>
    </tableComponents>

    <el-dialog :close-on-click-modal="false" title="编辑" class="tl size_13" width="800px" :visible.sync="dialogFormVisible">
      <el-form :model="edit_form" ref="form" label-width="120px">
        <el-form-item label="用户帐号：">
          <el-col :span="12">
            <el-input type="text" :rows="6" clearable placeholder="请输入" disabled v-model="edit_form.username" autocomplete="off"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="用户昵称：">
          <el-col :span="12">
            <el-input type="text" :rows="6" clearable placeholder="请输入" v-model="edit_form.nickname" autocomplete="off"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="电话：">
          <el-col :span="12">
            <el-input type="text" :rows="6" clearable placeholder="请输入" v-model="edit_form.tel" autocomplete="off"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="会员头像：">
          <el-col :span="12">
            <el-input v-model="edit_form.avatar" autocomplete="off" clearable class="mar_bottom_5" disabled></el-input>
            <uploadpic :piclink="edit_form.avatar" :width="150" :height="150" :real_width="150" :real_height="150" :is_more="false"
                @send_pic="edit_form.avatar = $event">
            </uploadpic>
          </el-col>
        </el-form-item>

        <el-form-item>
          <el-button :loading="$store.state.isLoading" type="primary" @click="editlive(edit_form)">编 辑</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- <keep-alive>
      <component :is="'xzuser'" :show="shows" :isAll="false" showType="list" @sendShop="getSend" @isshow="getShow"></component>
    </keep-alive> -->
  </div>
</template>
<script>
import xzuser from "@/components/currency/xz_user.vue";
import { liveCommentSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
import uploadpic from "@/components/page/pic/up_pic";
export default {
  data () {
    return {
      userSearchData: liveCommentSearchData,
      current: "",
      shows: false,
      is_edit: false,
      dialogFormVisible: false,
      edit_form: {
        piclink: ""
      },
      loading: false,
      list: [],
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      searchAll: {},
      row: {},
      multipleSelection: [],
      showCity: true
    };
  },
  components: {
    xzuser,
    uploadpic
  },
  methods: {
    change_switch (val, row, type) {
      var params = {};
      params.id = row.id;
      params[type] = val;
      this.$api.getim.edit_imuserlist(params).then(res => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess(res.data.result);
        } else {
          this.$fnc.alertError(res.data.result);
        }
      });
    },
    getShow (val) {
      this.shows = val;
    },
    getSend (row) {
      this.edit_form.username = row.username;
      this.edit_form.uid = row.id;
    },
    xzshop () {
      this.shows = true;
    },
    sorta (a, b) {
      return b - a;
    },
    sortNew (index, row) {
      var params = {};
      params = row;
      params.id = row.id;
      params.sort = row.sort;
      this.$api.getim.edit_imuserlist(params).then(res => {
        if (res.data.code == 200 && res.data.result) {
          return;
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
        }
      });
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },
    deleteAll () {
      //批量删除
      var str = "";
      if (this.multipleSelection.length <= 0) {
        this.$message.error("未选择批量删除");
      } else {
        for (var i in this.multipleSelection) {
          str += this.multipleSelection[i].id + "@";
        }
        str = str.slice(0, -1);
        this.$swal({
          title: "您确定要清空该IM账号吗",
          text: "清空后将无法恢复，请谨慎操作！",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "是的，我要删除",
          cancelButtonText: "容我三思"
        }).then(willDelete => {
          if (willDelete.value) {
            this.$api.getim.del_imuserlist({ id_str: str }).then(res => {
              if (res.data.code == 200) {
                this.$swal("删除成功！", res.data.result, "success");
                this.getNewsAll(this.searchAll);
              } else {
                this.$swal("删除失败！", res.data.result, "success");
                this.getNewsAll(this.searchAll);
              }
            });
          }
        });
      }
    },
    deletebtn (id) {
      //删除
      this.$swal({
        title: "您确定要清空该IM账号吗",
        text: "清空后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          this.$api.getim.del_imuserlist({ id: id }).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", res.data.result, "success");
              this.getNewsAll(this.searchAll);
            } else {
              this.$swal("删除失败！", res.data.result, "success");
              this.getNewsAll(this.searchAll);
            }
          });
        }
      });
    },
    add_data () {
      this.edit_form = {
        title: "",
        piclink: "",
        price: "0"
      };
      this.is_edit = false;
      this.dialogFormVisible = true;
    },
    onSuccess (pic) {
      console.log(pic);
      this.edit_form.piclink = pic;
    },
    getIs (val, row) {
      this.is_edit = true;
      var params = {};
      params = row;
      params.id = row.id;
      params.show = val;
      this.editlive(params);
    },

    editlive (item) {
      var params = {};

      if (this.is_edit == false) {
        params = item;
        this.$api.getim.add_imuserlist(params).then(res => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.$fnc.alertSuccess(res.data.result);
            this.getNewsAll(this.searchAll);
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      } else {
        params = item;
        var params2 = item
        // params2.id = item.id;
        // params2.nickname = item.nickname;
        // params2.avatar = item.avatar;
        // params2.tel = item.tel;
        this.$api.getim.modify_remark(params2).then(res => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.$fnc.alertSuccess(res.data.result);
            this.getNewsAll(this.searchAll);
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      }
    },
    editbtn (item) {
      this.is_edit = true;
      this.$api.getUser.userEdit({ id: item.id }).then(res => {
        if (res.data.code == 200) {
          this.edit_form = res.data.result;
          this.dialogFormVisible = true;
        }
      });
    },

    receive_search (obj) {
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    getNewsAll (data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      params.vid = this.$route.query.id;
      this.$api.getim.get_imuserlist(params).then(res => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    handleSizeChange (val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange (val) {
      this.currentPage = val;
      var params = this.searchAll;
      params.page = val;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
    },

    reload () {
      this.getNewsAll(this.searchAll);
    }
  },
  beforeCreate () { },
  created () {
    this.getNewsAll();
  },
  computed: {}
};
</script>

<style lang="less" scoped>
.myblank button {
  margin: 5px 5px 0 0;
}
</style>
